# coding=utf-8
# 导入re模块，直接调用来实现正则匹配
import re
import requests
# 定义变量url 获取要下载图片的地址
url = "http://tieba.baidu.com/p/2460150866"
# 使用get()来获取url
r = requests.get(url)
# print(r.text)
imglist = re.findall('src="(.+?\.jpg)" pic_ext',r.text)
print(imglist)

# 定义变量x并初始化用来计数图片的张数
x = 0
# 遍历
for imgurl in imglist:
    # 获取获得的从imglist中遍历得到的imgurl
    imgres = requests.get(imgurl)
    with open("image{}.jpg".format(x), "wb") as f:
        f.write(imgres.content)
        x +=1
        print("第", x ,"张")
print("下载完毕")